import { Router } from 'express';
import { ArtistController } from '../../admin/controllers/artistController';
import { authenticate, authorize } from '../../middleware/auth';
import { ALL_PERMISSIONS } from '../../constants/permissions';
import { uploadAvatar, uploadBanner } from '../../middleware/upload';

const router = Router();
const artistController = new ArtistController();

/**
 * @swagger
 * /api/admin/artists:
 *   get:
 *     summary: 获取艺人列表
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页数量
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           enum: [ACTIVE, INACTIVE]
 *         description: 艺人状态
 *       - in: query
 *         name: search
 *         schema:
 *           type: string
 *         description: 搜索关键词
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取艺人列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     list:
 *                       type: array
 *                       items:
 *                         $ref: '#/components/schemas/Artist'
 *                     pagination:
 *                       $ref: '#/components/schemas/Pagination'
 */
router.get('/', authenticate, authorize([ALL_PERMISSIONS.ARTIST_READ]), artistController.getArtists);

/**
 * @swagger
 * /api/admin/artists/{id}:
 *   get:
 *     summary: 获取艺人详情
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取艺人详情成功
 *                 data:
 *                   $ref: '#/components/schemas/Artist'
 */
router.get('/:id', authenticate, authorize([ALL_PERMISSIONS.ARTIST_READ]), artistController.getArtist);

/**
 * @swagger
 * /api/admin/artists:
 *   post:
 *     summary: 创建艺人
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *             properties:
 *               name:
 *                 type: string
 *                 description: 艺人名称
 *               description:
 *                 type: string
 *                 description: 艺人描述
 *               avatar:
 *                 type: string
 *                 description: 头像URL
 *               bannerImage:
 *                 type: string
 *                 description: 横幅图片URL
 *               genre:
 *                 type: string
 *                 description: 音乐流派
 *               country:
 *                 type: string
 *                 description: 国家/地区
 *     responses:
 *       201:
 *         description: 创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 创建艺人成功
 *                 data:
 *                   $ref: '#/components/schemas/Artist'
 */
router.post('/', authenticate, authorize([ALL_PERMISSIONS.ARTIST_CREATE]), artistController.createArtist);

/**
 * @swagger
 * /api/admin/artists/{id}:
 *   put:
 *     summary: 更新艺人信息
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *                 description: 艺人名称
 *               description:
 *                 type: string
 *                 description: 艺人描述
 *               avatar:
 *                 type: string
 *                 description: 头像URL
 *               bannerImage:
 *                 type: string
 *                 description: 横幅图片URL
 *               genre:
 *                 type: string
 *                 description: 音乐流派
 *               country:
 *                 type: string
 *                 description: 国家/地区
 *               status:
 *                 type: string
 *                 enum: [ACTIVE, INACTIVE]
 *                 description: 艺人状态
 *     responses:
 *       200:
 *         description: 更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 更新艺人信息成功
 *                 data:
 *                   $ref: '#/components/schemas/Artist'
 */
router.put('/:id', authenticate, authorize([ALL_PERMISSIONS.ARTIST_UPDATE]), artistController.updateArtist);

/**
 * @swagger
 * /api/admin/artists/{id}:
 *   delete:
 *     summary: 删除艺人
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 删除艺人成功
 */
router.delete('/:id', authenticate, authorize([ALL_PERMISSIONS.ARTIST_DELETE]), artistController.deleteArtist);

/**
 * @swagger
 * /api/admin/artists/statistics:
 *   get:
 *     summary: 获取艺人统计信息
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取艺人统计信息成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     overview:
 *                       type: object
 *                       properties:
 *                         totalArtists:
 *                           type: integer
 *                         activeArtists:
 *                           type: integer
 *                         totalPerformances:
 *                           type: integer
 *                         totalVotes:
 *                           type: integer
 *                     topArtists:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           artistId:
 *                             type: integer
 *                           artist:
 *                             $ref: '#/components/schemas/Artist'
 *                           voteCount:
 *                             type: integer
 *                           performanceCount:
 *                             type: integer
 *                     genreStats:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           genre:
 *                             type: string
 *                           count:
 *                             type: integer
 */
router.get('/statistics', authenticate, authorize([ALL_PERMISSIONS.ARTIST_READ]), artistController.getArtistStatistics);

/**
 * @swagger
 * /api/admin/artists/{id}/avatar:
 *   post:
 *     summary: 上传艺人头像
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               avatar:
 *                 type: string
 *                 format: binary
 *                 description: 头像文件
 *     responses:
 *       200:
 *         description: 上传成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 头像上传成功
 *                 data:
 *                   $ref: '#/components/schemas/Artist'
 */
router.post('/:id/avatar', authenticate, authorize([ALL_PERMISSIONS.ARTIST_UPDATE]), uploadAvatar, artistController.uploadAvatar);

/**
 * @swagger
 * /api/admin/artists/{id}/banner:
 *   post:
 *     summary: 上传艺人横幅图片
 *     tags: [Admin - Artists]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 艺人ID
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               bannerImage:
 *                 type: string
 *                 format: binary
 *                 description: 横幅图片文件
 *     responses:
 *       200:
 *         description: 上传成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 横幅上传成功
 *                 data:
 *                   $ref: '#/components/schemas/Artist'
 */
router.post('/:id/banner', authenticate, authorize([ALL_PERMISSIONS.ARTIST_UPDATE]), uploadBanner, artistController.uploadBanner);

export default router; 